#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

int findUpper(int num[], int size, int target)
{
    int lo = 0, hi = size -1;
    while(lo < hi) {
        int mid = lo+ (hi - lo)/2;
        if (num[mid] <= target) lo = mid+1;
        else hi = mid;
    }
    if (num[lo] == target) return lo;
    else return lo-1;
}

int findLower(int num[], int size, int target)
{
    int lo = 0, hi = size -1;
    while(lo < hi) {
        int mid = lo+ (hi - lo)/2;
        if (num[mid] >= target) hi = mid;
        else lo = mid+1;
    }
    if (num[lo] == target) return lo;
    else return lo+1;
}

int findRange(int num[], int size, int target)
{
    int upper = findUpper(num, size, target);
    int lower = findLower(num, size, target);
    cout << lower << " " << upper << endl;
    return upper - lower;
}

int main(int argc, char **argv)
{
    int A[] = {0,1,5,6,7,8,9};
    cout << findRange(A, sizeof(A)/sizeof(int), 5);

}
